import Vue from 'vue'
import VueRouter from 'vue-router'
import { checkLogin } from '../utils/checkLogin'
import store from '../store'

Vue.use(VueRouter)

const routes = [
  // 首页
  {
    path: '/',
    name: 'home',
    component: () => import(/* webpackChunkName: "home" */ '../views/home/Home.vue')
  },
  {
    path: '/layout',
    name: 'layout',
    component: () => import(/* webpackChunkName: "layout" */ '../layout/Layout.vue'),
    children: [
      // 高考避雷针
      {
        path: '/important',
        name: 'important',
        component: () => import(/* webpackChunkName: "important" */ '../views/important/Important.vue')
      },
      // 中国大学信息
      {
        path: '/universityInfo',
        name: 'universityInfo',
        component: () => import(/* webpackChunkName: "universityInfo" */ '../views/universityInfo/UniversityInfo.vue')
      },
      // 中国大学信息详情
      {
        path: '/universityInfoDetail',
        name: 'universityInfoDetail',
        component: () => import(/* webpackChunkName: "universityInfoDetail" */ '../views/universityInfoDetail/UniversityInfoDetail.vue')
      },
      // 公益合作大学
      {
        path: '/coUniversity',
        name: 'coUniversity',
        component: () => import(/* webpackChunkName: "coUniversity" */ '../views/coUniversity/CoUniversity.vue')
      },
      // 公益合作高中
      {
        path: '/coHighSchool',
        name: 'coHighSchool',
        component: () => import(/* webpackChunkName: "coHighSchool" */ '../views/coHighSchool/CoHighSchool.vue')
      },
      // 直播排期表
      {
        path: '/liveTable',
        name: 'liveTable',
        component: () => import(/* webpackChunkName: "liveTable" */ '../views/liveTable/LiveTable.vue')
      },
      // 直播详情
      {
        path: '/liveDetail',
        name: 'liveDetail',
        component: () => import(/* webpackChunkName: "liveDetail" */ '../views/liveDetail/LiveDetail.vue')
      },
      // 直播详情
      {
        path: '/videoPlay',
        name: 'videoPlay',
        component: () => import(/* webpackChunkName: "videoPlay" */ '../views/videoPlay/VideoPlay.vue')
      },
       // 直播详情
       {
        path: '/wuhanSchool',
        name: 'wuhanSchool',
        component: () => import(/* webpackChunkName: "videoPlay" */ '../views/wuhanSchool/wuhanSchool.vue')
      },
       // 直播详情
       {
        path: '/liveHistory',
        name: 'liveHistory',
        component: () => import(/* webpackChunkName: "videoPlay" */ '../views/liveHistory/liveHistory.vue')
      },
    ]
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  document.documentElement.scrollTop = 0
  const loginState = checkLogin()
  if (to.name === 'universityInfoDetail') {
    if (loginState) {
      next()
    } else {
      store.commit('ToggleLoginOpen', true)
    }
  } else {
    next()
  }
})

export default router
